/**
 * CS575 Software Design
 * Group 6
 * Group Members: Anthony Davidson, Kendra Scheesley, Lyndsey Whitman, Stephen Zakrewsky
 * Date: May 19, 2012
 * Main Author(s): Lyndsey Whitman
 */
package edu.drexel.cs575.a3;

import java.util.ArrayList;
import java.util.List;

public class WeighableItems implements WeighableItem
{

	private String				name;

	private List<WeighableItem>	childWeighableItems	= new ArrayList<WeighableItem>();

	public WeighableItems()
	{
		this.name = "";
	}

	public WeighableItems(String name)
	{
		this.name = name;
	}

	@Override
	public String getName()
	{
		return name;
	}

	@Override
	public void setName(String name)
	{
		this.name = name;
	}

	@Override
	public double getMass()
	{
		double mass = 0.0;

		for (WeighableItem item : this.childWeighableItems)
		{
			mass += item.getMass();
		}

		return mass;
	}

	@Override
	public double calculatePricePerMassUnit()
	{
		double price = 0.0;

		for (WeighableItem item : this.childWeighableItems)
		{
			price += item.calculatePricePerMassUnit();
		}

		return price;
	}

	// Adds the weighableItem to the composition.
	public void add(WeighableItem item)
	{
		this.childWeighableItems.add(item);
	}

	// Removes the weighableItem from the composition.
	public void remove(WeighableItem item)
	{
		this.childWeighableItems.remove(item);
	}

	public int getNumberOfItems()
	{
		int numItems = 0;

		for (WeighableItem item : this.childWeighableItems)
		{
			numItems += item.getNumberOfItems();
		}

		return numItems;
	}
}
